package com.wwwarehouse.financialcenter.adapter.moneyhouse;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wwwarehouse.financialcenter.R;
import com.wwwarehouse.financialcenter.bean.bindingcard.BankInfoBean;
import com.wwwarehouse.financialcenter.eventbus.BankInfoEvent;

import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * Description:
 * Copyright  : Copyright (c) 2017
 * Author     : yfwang
 * Date       : 2017/11/13 18:55
 */
public class BankBranchAdapter extends RecyclerView.Adapter<BankBranchAdapter.ViewHolder> {

    private Context mContext;
    private List<BankInfoBean.DataBean> list;
    private int mHeight = 0;

    public BankBranchAdapter(Context mContext, List<BankInfoBean.DataBean> list, int mHeight) {
        this.mContext = mContext;
        this.list = list;
        this.mHeight = mHeight;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.financial_center_bank_branch_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final BankInfoBean.DataBean dataBean = list.get(position);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.mListItem.getLayoutParams();
        params.height =mHeight / 9;
        holder.mBankBranch.setText(dataBean.getSubbankName());

        holder.mListItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new BankInfoEvent(dataBean));
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {


        private TextView mBankBranch;
        private RelativeLayout mListItem;

        public ViewHolder(View view) {
            super(view);
            mBankBranch = (TextView) view.findViewById(R.id.tv_bank_branch);
            mListItem = (RelativeLayout) view.findViewById(R.id.rel_item);
        }
    }
}
